using System;
using System.Xml.Serialization;

namespace Kotonoha.Objects.SuperMemo {
    public class ItemLearningData : IEquatable<ItemLearningData> {

        public ItemLearningData() {
            id = 0;
            difficulty = 2.5;
        }

        private long id;
        [XmlIgnore]
        public virtual long Id {
            get { return id; }
            set { id = value; }
        }

        [XmlAttribute]
        public virtual DateTime IntervalStart { get; set; }

        [XmlAttribute]
        public virtual DateTime IntervalEnd { get; set; }

        [XmlAttribute]
        public virtual double IntervalLength { get; set; }

        /// <summary>
        /// How many times this item was forgotten
        /// </summary>
        [XmlAttribute]
        public virtual int Lapse { get; set; }

        [XmlAttribute]
        public virtual int Repetition { get; set; }

        private double difficulty;
        [XmlAttribute]
        public virtual double Difficulty {
            get { return difficulty; }
            set { difficulty = value; }
        }

        #region Equality Members

        public virtual bool Equals(ItemLearningData other) {
            if (ReferenceEquals(null, other)) {
                return false;
            }
            if (ReferenceEquals(this, other)) {
                return true;
            }
            return other.id == id;
        }

        public override bool Equals(object obj) {
            if (ReferenceEquals(null, obj)) {
                return false;
            }
            if (ReferenceEquals(this, obj)) {
                return true;
            }
            if (obj.GetType() != typeof(ItemLearningData)) {
                return false;
            }
            return Equals((ItemLearningData)obj);
        }

        public override int GetHashCode() {
            return id.GetHashCode();
        }

        #endregion

    }
}